package com.shambles.manage.serviceImpl;

import com.shambles.manage.mapper.AccessMapper;
import com.shambles.manage.mapper.User_AssetMapper;
import com.shambles.manage.mapper.UsersMapper;
import com.shambles.manage.model.Access;
import com.shambles.manage.model.User_Asset;
import com.shambles.manage.model.Users;
import com.shambles.manage.service.UserService;
import com.shambles.manage2.tkmapper.entity.Usersinfo;
import com.shambles.manage2.tkmapper.mapper.UsersinfoMapper;
import com.shambles.weixin.base.SNSUserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service("userService")
public class UserServiceImpl implements UserService {
    private UsersMapper usersMapper;         //操作用户信息

    private User_AssetMapper user_AssetMapper;

    private AccessMapper accessMapper;

    @Resource
    private UsersinfoMapper usersinfoMapper;

    @Autowired
    public void setUsersMapper(UsersMapper usersMapper) {
        this.usersMapper = usersMapper;
    }

    @Autowired
    public void setUser_AssetMapper(User_AssetMapper user_AssetMapper) {
        this.user_AssetMapper = user_AssetMapper;
    }

    @Autowired
    public void setAccessMapper(AccessMapper accessMapper) {
        this.accessMapper = accessMapper;
    }

    @Override
    public List<Users> getAllFullUser(Integer campusId,Integer limit, Integer offset, String sort,
                                      String order,String search) {
        return usersMapper.getAllFullUser(campusId,limit,offset,sort,order,search);
    }

    @Override
    public Integer getUserCount(String campusAdmin ,Integer campusId,String search) {
        return usersMapper.getUserCount(campusAdmin,campusId,search);
    }

    @Override
    public Integer getUserFullCount(Integer campusId,String search) {
        return usersMapper.getUserFullCount(campusId,search);
    }



    @Override
    public Integer getOpenId(Integer campusId, String openId) {
        // TODO Auto-generated method stub
        return usersMapper.getOpenId(campusId, openId);
    }

    @Override
    public Integer insertUser(SNSUserInfo snsUserInfo) {
        // TODO Auto-generated method stub
        return usersMapper.insertUserInfo(snsUserInfo);
    }

    @Override
    public Users getUserInfoById(Integer campusId, String openId) {
        // TODO Auto-generated method stub
        return usersMapper.getUserByOpenId(campusId, openId);
    }

    @Override
    public Integer upUserByOpenId(SNSUserInfo snsUserInfo) {
        // TODO Auto-generated method stub
        return usersMapper.upUserByOpenId(snsUserInfo);
    }

    @Override
    public Integer upsubscribeByOpenId(Map<String, Object> paramterMap) {
        // TODO Auto-generated method stub
        return usersMapper.upsubscribeByOpenId(paramterMap);
    }

    @Override
    public int upAtionFormatter(Map<String, Object> paramterMap) {
        // TODO Auto-generated method stub
        return usersMapper.upAtionFormatter(paramterMap);
    }

    @Override
    public int selectRepeatUser(String name) {
        // TODO Auto-generated method stub
        return usersMapper.selectRepeatUser(name);
    }

    @Override
    public int selectRepeatUserByOpenId(String openId) {
        // TODO Auto-generated method stub
        return usersMapper.selectRepeatUserByOpenId(openId);
    }

    @Override
    public int insertUsersInfo(Users users) {
        // TODO Auto-generated method stub
        return usersMapper.insertUsersInfo(users);
    }

    @Override
    public int updateUsersInfo(Users users) {
        // TODO Auto-generated method stub
        return usersMapper.updateUsersInfo(users);
    }

    @Override
    public Users getUserByOnlyOpenId(String openId) {
        // TODO Auto-generated method stub
        return usersMapper.getUserByOnlyOpenId(openId);
    }

    @Override
    public User_Asset selectUser_AssetByOpenId(String openId) {
        // TODO Auto-generated method stub
        return user_AssetMapper.selectByPrimaryKey(openId);
    }

    @Override
    public int insertIntoUser_AssetByOpenId(User_Asset user_Asset) {
        // TODO Auto-generated method stub
        return user_AssetMapper.insert(user_Asset);
    }

    @Override
    public int updateUser_AssetByOpenId(User_Asset user_Asset) {
        // TODO Auto-generated method stub
        return user_AssetMapper.updateByPrimaryKeySelective(user_Asset);
    }

    @Override
    public int getCountUser_AssetByOpenId(String openId) {
        // TODO Auto-generated method stub
        return user_AssetMapper.getCountUser_AssetByOpenId(openId);
    }

    @Override
    public List<Users> getUserByPhone(Integer limit, Integer offset, String sort, String order) {
        // TODO Auto-generated method stub
        return usersMapper.getUserByPhone(limit, offset, sort, order);
    }

    @Override
    public List<Users> getUserByGuidance() {
        // TODO Auto-generated method stub
        return usersMapper.getUserByGuidance();
    }

    @Override
    public List<Users> getUserByPlace(Integer place) {
        // TODO Auto-generated method stub
        return usersMapper.getUserByPlace(place);
    }

    @Override
    public List<Users> getWetchatAllUsers(Integer campusId,Integer place,Integer limit,Integer offset, String sort,String order) {
        // TODO Auto-generated method stub
        return usersMapper.getWetchatAllUsers(campusId, place,limit,offset,sort,order);
    }

    @Override
    public int insertAccess(Access access) {
        // TODO Auto-generated method stub
        return accessMapper.insert(access);
    }

    @Override
    public Map selectAllAccess(Integer campusId, Integer limit, Integer offset, String sort, String order,
                               String search,String page) {
        // TODO Auto-generated method stub

        if(sort!=null&&sort.equals("accessTime")){
            sort="access_time";
        }else{
            sort="access_time";
        }

        if(order!=null&&order.equals("asc")){
            order="asc";
        }

        if(order!=null&&order.equals("desc")){
            order="desc";
        }

        List list=accessMapper.selectAllAccess(campusId, limit, offset, sort, order, search,page);

        int total=accessMapper.selectCountAccess(campusId, search,page);

        Map map=new HashMap<>();

        map.put("rows", list);

        map.put("total", total);

        return map;
    }

    @Override
    public Users getUserByAssetCharter(String charter, String idNo) {
        // TODO Auto-generated method stub

        return usersMapper.getUserByAssetCharter(charter, idNo);

    }

    @Override
    public Usersinfo selectUserInfoByOpenId(String openId) {

        return usersinfoMapper.selectUserInfoByOpenId(openId);
    }

    @Override
    public int getCountUserInfoByOpenId(String openId) {
        Usersinfo usersinfo = new Usersinfo();
        usersinfo.setOpenId(openId);
        return usersinfoMapper.selectCount(usersinfo);
    }

    @Override
    public int updateUserInfoByOpenId(Usersinfo usersInfo) {
        return usersinfoMapper.updateUserInfoByOpenId(usersInfo);
    }

    @Override
    public int insertIntoUserInfoByOpenId(Usersinfo usersInfo) {
        return usersinfoMapper.insert(usersInfo);
    }

}
